package com.tf_cut.admin.sys.sysuser.repository;

import com.tf_cut.admin.common.repository.*;
import com.tf_cut.admin.sys.sysuser.pojo.SysUser;

import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface SysUserRepository extends CommonRepository<SysUser, String> {
    SysUser findByLoginName(String username);
    
    @Query(value = "select * from sys_user where user_id = ?1",nativeQuery=true)
    SysUser queryAppKey(String loginId);
    
	@Query(value = "SELECT count(*) FROM admin.sys_user s LEFT JOIN backend.person_info p ON s.user_id = p.login_id  left join backend.seller_info i on s.user_id = i.login_id WHERE s.login_name = ?1 AND (p.card_status != 'N' or i.is_authentication != 'N')" ,nativeQuery=true)
    Integer queryByLoginName(String username);

	@Query(value = "select * from admin.sys_user where login_name = ?1" ,nativeQuery=true)
	SysUser queryByMobile(String mobile);

	@Query(value = "select person_id from backend.person_info where login_name = ?1 and login_id != '' limit 1" ,nativeQuery=true)
	String findByPersonId(String mobile);

	@Query(value = "SELECT count(*) FROM admin.sys_user s WHERE s.login_name = ?1" ,nativeQuery=true)
	int findByMobile(String sellerMobile);
    
}
